cmake_minimum_required(VERSION 3.27)

project(d2s-cli LANGUAGES CXX C)

#QTDIR=X:/Qt/6.7.2/msvc2019_64
list(APPEND CMAKE_PREFIX_PATH $ENV{QTDIR})
set(CMAKE_CXX_STANDARD 20)


add_subdirectory(lwip_core)
add_subdirectory(base)
add_subdirectory(tomlplusplus)
add_subdirectory(reflect-cpp)

add_executable(d2s-cli WIN32
    main.cpp
    ring_buf.hpp
    ring_buf_impl.hpp
    netpacket_pool.h
    spsc_queue.h
    io.hpp
    socks_client.hpp
    lwipstack.h
    lwipstack.cpp
    # iocontext.h
    # iocontext.cpp
    type_traits.h
    coro_io.hpp
    io_context_pool.hpp
    driver2socks.h
    driver2socks.cpp
    asio_coro_util.hpp
    lwip/sys_arch.h
    lwip/sys_arch.cpp
    app_config.h
    windivert_driver.h
    windivert_driver.cpp
    mpmc_queue.h
    concurrentqueue.h
    adapters_info.h
    crc32.h crc32.cpp
    vcpkg.json
    socks_connect.h
    wintun_driver.h wintun_driver.cpp

)

find_package(Qt6 REQUIRED COMPONENTS Core)
find_package(asio CONFIG REQUIRED)
# find_package(nlohmann_json CONFIG REQUIRED)
find_package(async_simple CONFIG REQUIRED)
# find_package(reflectcpp CONFIG REQUIRED)

target_include_directories(d2s-cli PUBLIC
    lwip_core/src/include
    ../driver/common
    lwip
    base
)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
        "../../../driver/x64/Debug/WinDivertLiteDll"
    )
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR CMAKE_BUILD_TYPE STREQUAL "Release")
    target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
        "../../../driver/x64/Release/WinDivertLiteDll"
    )
endif()
target_link_libraries(d2s-cli PUBLIC
    Qt6::Core
    async_simple::async_simple_header_only
    reflectcpp
    base
    lwipcore Winmm Iphlpapi)

target_compile_options(d2s-cli PRIVATE /utf-8)
target_compile_definitions(d2s-cli PRIVATE WIN32_LEAN_AND_MEAN)
target_link_options(d2s-cli PRIVATE "/entry:mainCRTStartup")
